package com.justnow.offer;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author justnow
 * Created on 2020-09-16
 * Description
 */
public class Test31 {
    List<List<Integer>> res = new LinkedList<>();
    public List<List<Integer>> combine(int n, int k) {
        dfs(n, k, 1, new LinkedList<>());
        return res;
    }

    public void dfs(int n, int k, int begin, List<Integer> list) {
        if (list.size() == n) {
            res.add(list);
        }
        for (int i = begin; i <= n; i++) {
            list.add(i);
            dfs(n, k, begin + 1, list);
            list.remove(list.size() - 1);
        }
    }

    public static void main(String[] args) {
        Solution31 solution31 = new Solution31();
        int n = 4;
        int k = 2;
        List<List<Integer>> combine = solution31.combine(n, k);
        System.out.println(combine);
    }

}
